package com.naiterui.ehp.bs.doctor.vo;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.base.MoreObjects;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 医生执业证信息VO
 *
 * @author 王泽浩
 * @since 1.0.0
 */
@SuppressWarnings("unused")
@ApiModel(value = "MedicalLicenseParam", description = "医生执业证信息VO")
public class MedicalLicenseParam implements java.io.Serializable {

    private static final Logger LOGGER = LoggerFactory.getLogger(MedicalLicenseParam.class);

    /**
     * 医师执业证类型 新版本
     */
    public static final int VERSION_TYPE_NEW = 1;

    /**
     * 医师执业证类型 旧版本
     */
    public static final int VERSION_TYPE_OLD = 2;

    private static final long serialVersionUID = -8540982402633413447L;

    /**
     * 医师执业证号
     */
    @ApiModelProperty(value = "医师执业证号")
    private String number;

    /**
     * 医师执业证(1:新版,2:旧版本)
     */
    @ApiModelProperty(value = "医师执业证类型(1:新版,2:旧版本)")
    private Integer versionType;

    /**
     * 医师执业证(如果是旧版本的话,此字段是照片页,如果是新版本的话,使用此字段上传)
     */
    @ApiModelProperty(value = "医师执业证(如果是旧版本的话,此字段是照片页,如果是新版本的话,使用此字段上传)")
    private MultipartFile photoPage;

    /**
     * 旧版本医师资格证书信息页
     */
    @ApiModelProperty(value = "旧版本医师执业证信息页")
    private MultipartFile infoPage;

    public void validater() throws BusinessException {

        // 判断执业资格证号是否属于范围内
        if (StringUtils.isEmpty(number) || number.length() < 1 || number.length() > 27) {
            throw new BusinessException(ExceptionCodes.PARAM_ERROR_MEDICAL_NUM);
        }

        // 判断versionType 是否为0 1
        if (versionType == VERSION_TYPE_NEW) {

            // 判断文件是否上传
            if (photoPage == null) {
                LOGGER.warn("医生资质上传失败,照片页缺失");
                throw new BusinessException(ExceptionCodes.PARAM_ERROR);
            }

            this.infoPage = null;

        } else if (versionType == VERSION_TYPE_OLD) {

            // 判断文件是否上传
            if (photoPage == null || infoPage == null) {
                LOGGER.warn("医生资质上传失败,照片页缺失或资料页缺失");
                throw new BusinessException(ExceptionCodes.PARAM_ERROR);
            }

        } else {
            LOGGER.warn("医生资质上传失败，未知证件类型");
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);

        }

    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public Integer getVersionType() {
        return versionType;
    }

    public void setVersionType(Integer versionType) {
        this.versionType = versionType;
    }

    public MultipartFile getPhotoPage() {
        return photoPage;
    }

    public void setPhotoPage(MultipartFile photoPage) {
        this.photoPage = photoPage;
    }

    public MultipartFile getInfoPage() {
        return infoPage;
    }

    public void setInfoPage(MultipartFile infoPage) {
        this.infoPage = infoPage;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).add("number", number).add("versionType", versionType).add("photoPage", photoPage)
                          .add("infoPage", infoPage)
                          .toString();
    }
}
